package com.sf.tools.generate;
import java.io.File;

import com.sf.tools.common.Common;

public class BuildExcelExport {

	private static StringBuffer ExcelHeaderConfig_buff = new StringBuffer();
	private static StringBuffer ExcelHeaderConfig_sb = new StringBuffer();
	
	private static StringBuffer ExcelNameConfig_buff = new StringBuffer();
	private static StringBuffer ExcelNameConfig_sb = new StringBuffer();
	
	private static StringBuffer buff = new StringBuffer();
	
	public static void create(int index,boolean isLastNext){
		create_ExcelHeaderConfig(index,isLastNext);
		create_ExcelNameConfig(index,isLastNext);
		if(0 == index){
			create_ExcelColumn();
			create_processor_Date();
			create_processor_Float();
			create_processor_Number();
			create_PoiUtil();
			create_CommonUtil();
		}
	}

	private static void create_ExcelColumn(){
		buff = new StringBuffer();
		buff.append("package com.sf.module."+Common.MODULE_NAME+".excel;").append("\n")
			.append("").append("\n")
			.append("import java.io.Serializable;").append("\n")
			.append("/**").append("\n")
			.append(" * ").append("\n")
			.append(" * <pre>").append("\n")
			.append(" * *********************************************").append("\n")
			.append(" * @Copyright sf-express.").append("\n")
			.append(" * All rights reserved.").append("\n")
			.append(" * @Title:ExcelColumn.java").append("\n")
			.append(" * @Package com.sf.module."+Common.MODULE_NAME+".excel ").append("\n")
			.append(" * @Description: EXCEL 导出pojo").append("\n")
			.append(" * @author 613413").append("\n")
			.append(" * HISTORY").append("\n")
			.append(" * *********************************************").append("\n")
			.append(" *  ID     DATE          PERSON          REASON").append("\n")
			.append(" *  1      2014-5-23     613413         创建").append("\n")
			.append(" * *********************************************").append("\n")
			.append(" * </pre>").append("\n")
			.append(" */").append("\n")
			.append("public class ExcelColumn implements Serializable {").append("\n")
			.append("\t").append("private static final long serialVersionUID = -2656993045795635246L;").append("\n")
			.append("\t").append("private String id;//ID").append("\n")
			.append("\t").append("private String code;//英文名称").append("\n")
			.append("\t").append("private String name;//中文名称").append("\n")
			.append("\t").append("private String columncode;//数据库名").append("\n")
			.append("\t").append("private String columntype;//数据库类型").append("\n")
			.append("\t").append("private String fieldname;//处理数据的对象属性名").append("\n")
			.append("\t").append("private String header;").append("\n")
			.append("\t").append("private String dataIndex;").append("\n")
			.append("\t").append("private String width;").append("\n")
			.append("\t").append("private String display = null;//是否显示").append("\n")
			.append("\t").append("private String timeFormat = null;//时间格式化").append("\n")
			.append("\t").append("").append("\n")
			.append("\t").append("public String getId() {").append("\n")
			.append("\t\t").append("return id;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setId(String id) {").append("\n")
			.append("\t\t").append("this.id = id;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getCode() {").append("\n")
			.append("\t\t").append("return code;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setCode(String code) {").append("\n")
			.append("\t\t").append("this.code = code;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getName() {").append("\n")
			.append("\t\t").append("return name;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setName(String name) {").append("\n")
			.append("\t\t").append("this.name = name;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getColumncode() {").append("\n")
			.append("\t\t").append("return columncode;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setColumncode(String columncode) {").append("\n")
			.append("\t\t").append("this.columncode = columncode;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getColumntype() {").append("\n")
			.append("\t\t").append("return columntype;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setColumntype(String columntype) {").append("\n")
			.append("\t\t").append("this.columntype = columntype;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getFieldname() {").append("\n")
			.append("\t\t").append("return fieldname;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setFieldname(String fieldname) {").append("\n")
			.append("\t\t").append("this.fieldname = fieldname;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getHeader() {").append("\n")
			.append("\t\t").append("return header;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setHeader(String header) {").append("\n")
			.append("\t\t").append("this.header = header;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getDataIndex() {").append("\n")
			.append("\t\t").append("return dataIndex;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setDataIndex(String dataIndex) {").append("\n")
			.append("\t\t").append("this.dataIndex = dataIndex;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getWidth() {").append("\n")
			.append("\t\t").append("return width;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setWidth(String width) {").append("\n")
			.append("\t\t").append("this.width = width;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getDisplay() {").append("\n")
			.append("\t\t").append("return display;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setDisplay(String display) {").append("\n")
			.append("\t\t").append("this.display = display;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public String getTimeFormat() {").append("\n")
			.append("\t\t").append("return timeFormat;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("public void setTimeFormat(String timeFormat) {").append("\n")
			.append("\t\t").append("this.timeFormat = timeFormat;").append("\n")
			.append("\t").append("}").append("\n")
			.append("}").append("\n");

		File file = new File(Common.SAVE_PATH+File.separator+"excel");
		if(!file.exists()){
			file.mkdirs();
		}
		Common.write(new File(file,"ExcelColumn.java"), buff.toString());
		
		System.out.println("ExcelColumn.java 已生成.....");
	}

	private static void create_ExcelHeaderConfig(int index, boolean isLastNext){
		if(0 == index){
			ExcelHeaderConfig_sb = new StringBuffer();
			ExcelHeaderConfig_buff = new StringBuffer();
			ExcelHeaderConfig_buff.append("package com.sf.module."+Common.MODULE_NAME+".excel;").append("\n")
			.append("").append("\n")
			.append("import java.lang.reflect.Field;").append("\n")
			.append("import java.util.ArrayList;").append("\n")
			.append("").append("\n")
			.append("import org.slf4j.Logger;").append("\n")
			.append("import org.slf4j.LoggerFactory;").append("\n")
			.append("").append("\n")
			.append("/**").append("\n")
			.append("* <pre>").append("\n")
			.append("* *********************************************").append("\n")
			.append("* Copyright sf-express.").append("\n")
			.append("* All rights reserved.").append("\n")
			.append("* Description: Excel 表头设置").append("\n")
			.append("* HISTORY").append("\n")
			.append("* *********************************************").append("\n")
			.append("*  ID     DATE          PERSON          REASON").append("\n")
			.append("*  1      2014-05-23    613413         创建").append("\n")
			.append("* *********************************************").append("\n")
			.append("* </pre>").append("\n")
			.append("*/").append("\n")
			.append("public class ExcelHeaderConfig {").append("\n")
			.append("\t").append("private static final Logger log = LoggerFactory.getLogger(ExcelHeaderConfig.class);").append("\n")
			.append("\t").append("public static class ExcelArr{").append("\n")
			.append("\t\t").append("/********************  数组说明  *******************").append("\n")
			.append("\t\t").append(" * 第1项    实体类对应字段").append("\n")
			.append("\t\t").append(" * 第2项    Excel导出字段中文名").append("\n")
			.append("\t\t").append(" * 第3项    Excel导出宽度 (和Excel宽度参数相同)").append("\n")
			.append("\t\t").append(" * 第4项    时间格式化样式 (比如：\"yyyy-MM-dd hh:mm:ss\") 非时间字段设置为空").append("\n")
			.append("\t\t").append(" */").append("\n")
			.append("\t\t").append("").append("\n")
			.append("ExcelHeaderConfig-MARK")
			.append("\t").append("}").append("\n")
			.append("\t").append("/**").append("\n")
			.append("\t").append(" * ").append("\n")
			.append("\t").append(" * @Title: getExcelHeaderArr ").append("\n")
			.append("\t").append(" * @Description: 通过Name获取对应的Excel表头数组").append("\n")
			.append("\t").append(" * @param name").append("\n")
			.append("\t").append(" * @return").append("\n")
			.append("\t").append(" * @return String[][]").append("\n")
			.append("\t").append(" * @user 613413").append("\n")
			.append("\t").append(" * @date 2014-5-29").append("\n")
			.append("\t").append(" */").append("\n")
			.append("\t").append("public static String[][] getExcelHeaderArr(String name){").append("\n")
			.append("\t\t").append("String[][] arr = null;").append("\n")
			.append("\t\t").append("try {  ").append("\n")
			.append("\t\t\t").append("String className = ExcelHeaderConfig.class.getName()+\"$ExcelArr\";  ").append("\n")
			.append("\t\t\t").append("Class<?> c = Class.forName(className);  ").append("\n")
			.append("\t\t\t").append("Field f = c.getField(name);   ").append("\n")
			.append("\t\t\t").append("arr = (String[][]) f.get(new ExcelArr());").append("\n")
			.append("\t\t").append("} catch (Exception e) {  ").append("\n")
			.append("\t\t\t").append("log.error(\"\",e);").append("\n")
			.append("\t\t").append("}  ").append("\n")
			.append("\t\t").append("return arr;").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("/**").append("\n")
			.append("\t").append(" * @Title: getExcelHeaderList ").append("\n")
			.append("\t").append(" * @Description: Excel表头数组转List").append("\n")
			.append("\t").append(" * @param name").append("\n")
			.append("\t").append(" * @return").append("\n")
			.append("\t").append(" * @return ArrayList<gridcolumn>").append("\n")
			.append("\t").append(" * @user 613413").append("\n")
			.append("\t").append(" * @date 2014-5-29").append("\n")
			.append("\t").append(" */").append("\n")
			.append("\t").append("public static ArrayList<ExcelColumn> getExcelHeaderList(String name, String displayColumn){").append("\n")
			.append("\t\t").append("String[][] arr = ExcelHeaderConfig.getExcelHeaderArr(name);").append("\n")
			.append("\t\t").append("ArrayList<ExcelColumn> list = new ArrayList<ExcelColumn>();").append("\n")
			.append("\t\t").append("for (int i = 0; arr!=null && i < arr.length; i++) {").append("\n")
			.append("\t\t\t").append("ExcelColumn gridcolumn = new ExcelColumn();").append("\n")
			.append("\t\t\t").append("if(arr[i].length < 0)continue;").append("\n")
			.append("\t\t\t").append("if(arr[i].length >= 1)gridcolumn.setCode(arr[i][0]);").append("\n")
			.append("\t\t\t").append("if(arr[i].length >= 2)gridcolumn.setName(arr[i][1]);").append("\n")
			.append("\t\t\t").append("if(arr[i].length >= 3)gridcolumn.setWidth(arr[i][2]);").append("\n")
			.append("\t\t\t").append("if(arr[i].length >= 4)gridcolumn.setTimeFormat(arr[i][3]);").append("\n")
			.append("\t\t\t").append("if(arr[i].length >= 5)gridcolumn.setColumntype(arr[i][4]);").append("\n")
			.append("\t\t\t").append("if(displayColumn!=null && displayColumn.contains(\"|\"+i+\"|\")){").append("\n")
			.append("\t\t\t\t").append("gridcolumn.setDisplay(\"false\");").append("\n")
			.append("\t\t\t").append("}").append("\n")
			.append("\t\t\t").append("list.add(gridcolumn);").append("\n")
			.append("\t\t").append("}").append("\n")
			.append("\t\t").append("return list; ").append("\n")
			.append("\t").append("}").append("\n")
			.append("}").append("\n");
		}
		
		ExcelHeaderConfig_sb.append("\t\t").append("/**").append("\n")
			.append("\t\t").append(" * "+Common.DOMAIN_DESC).append("\n")
			.append("\t\t").append(" */").append("\n")
			.append("\t\t").append("public String[][] "+Common.DOMAIN_NAME+" = {").append("\n");
		for(int i=0;i<Common.SHOW.size();i++){
			String desc = Common.getQueryDesc(Common.SHOW.get(i));
			if(desc.indexOf("(") != -1){
				desc = desc.substring(0,desc.indexOf("(")).trim();
			}
			if("Date".equalsIgnoreCase(Common.getQueryType(Common.SHOW.get(i)))){
				ExcelHeaderConfig_sb.append("\t\t\t").append("{\""+Common.SHOW.get(i)+"\",\""+desc+"\",\"12\",\"yyyy-MM-dd\"},");
			}else{
				if(Common.MAPPING.containsKey(Common.TABLE_NAME+":"+Common._COLUMN.get(Common._FIELD.indexOf(Common.SHOW.get(i))))){
					String mappInfo = Common.MAPPING.get(Common.TABLE_NAME+":"+Common._COLUMN.get(Common._FIELD.indexOf(Common.SHOW.get(i))));
					String mappingTableName = mappInfo.split(":")[0];
//					String mappingColumn = mappInfo.split(":")[1];
					String mappingColumnName = mappInfo.split(":")[2];
					String mappingEntityName = Common.getEntityName(mappingTableName);
					String mappingPropName = (mappingEntityName.charAt(0)+"").toLowerCase()+mappingEntityName.substring(1);
					
					mappingColumnName = Common.getFieldName(mappingColumnName);
					
					ExcelHeaderConfig_sb.append("\t\t\t").append("{\""+mappingPropName+"."+mappingColumnName+"\",\""+desc+"\",\"12\"},");
					
				}else{
					ExcelHeaderConfig_sb.append("\t\t\t").append("{\""+Common.SHOW.get(i)+"\",\""+desc+"\",\"12\"},");
				}
			}
			if(i == Common.SHOW.size()-1){
				ExcelHeaderConfig_sb = new StringBuffer(ExcelHeaderConfig_sb.substring(0, ExcelHeaderConfig_sb.length()-1));
			}
			ExcelHeaderConfig_sb.append("\n");
		}
		ExcelHeaderConfig_sb.append("\t\t").append("};").append("\n\n");
		
		if(isLastNext){
			String content = ExcelHeaderConfig_buff.toString().replace("ExcelHeaderConfig-MARK", ExcelHeaderConfig_sb);
			File file = new File(Common.SAVE_PATH+File.separator+"excel");
			if(!file.exists()){
				file.mkdirs();
			}
			Common.write(new File(file,"ExcelHeaderConfig.java"), content);
			
			System.out.println("ExcelHeaderConfig.java 已生成.....");
		}
	}
	
	private static void create_ExcelNameConfig(int index, boolean isLastNext){
		if(0 == index){
			ExcelNameConfig_buff = new StringBuffer();
			ExcelNameConfig_sb = new StringBuffer();
			
			ExcelNameConfig_buff.append("package com.sf.module."+Common.MODULE_NAME+".excel;").append("\n")
			.append("").append("\n")
			.append("import java.lang.reflect.Field;").append("\n")
			.append("/**").append("\n")
			.append(" * ").append("\n")
			.append(" * <pre>").append("\n")
			.append(" * *********************************************").append("\n")
			.append(" * @Copyright sf-express.").append("\n")
			.append(" * All rights reserved.").append("\n")
			.append(" * @Title:GswmgmtType.java").append("\n")
			.append(" * @Package com.sf.module."+Common.MODULE_NAME+".excel ").append("\n")
			.append(" * @Description: Excel导出名称命名处理Type").append("\n")
			.append(" * @author 613413").append("\n")
			.append(" * HISTORY").append("\n")
			.append(" * *********************************************").append("\n")
			.append(" *  ID     DATE          PERSON          REASON").append("\n")
			.append(" *  1      2014-6-18     613413         创建").append("\n")
			.append(" * *********************************************").append("\n")
			.append(" * </pre>").append("\n")
			.append(" */").append("\n")
			.append("public class ExcelNameConfig {").append("\n")
			.append("\t").append("public static final class LabelType {").append("\n")
			.append("\t\t").append("public static String Code = \"Code\";").append("\n")
			.append("\t\t").append("public static String Name = \"Name\";").append("\n")
			.append("\t").append("}").append("\n")
			.append("\t").append("/*******************  定义说明  ********************").append("\n")
			.append("\t").append(" * 第一项 和处理对象的实体名称相同 比如：对应 EmpSchSit 名称 EmpSchSit").append("\n")
			.append("\t").append(" * 第二项 扩展参数 命名：第一项的名称+s").append("\n")
			.append("\t").append(" *\t\t 比如：EmpSchSit 对应 EmpSchSits").append("\n")
			.append("\t").append(" *\t\t 默认两个参数：Code 英文名称").append("\n")
			.append("\t").append(" *\t\t\t\t\t   Name 中文名称 ").append("\n")
			.append("\t").append(" * ").append("\n")
			.append("\t").append(" */").append("\n")
			.append("\t").append("public static class ExcelName {").append("\n")
			.append("\t\t").append("").append("\n")
			.append("ExcelNameConfig-MARK")
			.append("\t").append("}").append("\n")
			.append("").append("\n")
			.append("\t").append("public static String getExcelName(String ExcelName, String LabelType) {").append("\n")
			.append("\t\t").append("String name = null;").append("\n")
			.append("\t\t").append("try {").append("\n")
			.append("\t\t\t").append("String className = ExcelNameConfig.class.getName() + \"$ExcelName$\"").append("\n")
			.append("\t\t\t\t\t").append("+ ExcelName + \"s\";").append("\n")
			.append("\t\t\t").append("Class<?> c = Class.forName(className);").append("\n")
			.append("\t\t\t").append("Field f = c.getField(LabelType);").append("\n")
			.append("\t\t\t").append("name = f.get(null).toString();").append("\n")
			.append("\t\t").append("} catch (Throwable e) {").append("\n")
			.append("\t\t\t").append("System.err.println(e);").append("\n")
			.append("\t\t").append("}").append("\n")
			.append("\t\t").append("return name;").append("\n")
			.append("\t").append("}").append("\n")
			.append("}").append("\n");
		}
		
		ExcelNameConfig_sb.append("\t\t").append("/* "+Common.DOMAIN_DESC+" */").append("\n")
		.append("\t\t").append("public static String "+Common.DOMAIN_NAME+" = \""+Common.DOMAIN_NAME+"\";").append("\n")
		.append("\t\t").append("public static class "+Common.DOMAIN_NAME+"s {").append("\n")
		.append("\t\t\t").append("public static String Code = \""+Common.DOMAIN_NAME+"\";").append("\n")
		.append("\t\t\t").append("public static String Name = \""+Common.DOMAIN_DESC+"\";").append("\n")
		.append("\t\t").append("}").append("\n\n");
		
		if(isLastNext){
			String content = ExcelNameConfig_buff.toString().replace("ExcelNameConfig-MARK", ExcelNameConfig_sb);
			File file = new File(Common.SAVE_PATH+File.separator+"excel");
			if(!file.exists()){
				file.mkdirs();
			}
			Common.write(new File(file,"ExcelNameConfig.java"), content);
			
			System.out.println("ExcelNameConfig.java 已生成.....");
		}
	}
	
	private static void create_processor_Date(){
		buff = new StringBuffer();
		buff.append("package com.sf.module."+Common.MODULE_NAME+".excel.processors;").append("\n")
		.append("").append("\n")
		.append("import java.text.SimpleDateFormat;").append("\n")
		.append("import java.util.Date;").append("\n")
		.append("").append("\n")
		.append("import net.sf.json.JsonConfig;").append("\n")
		.append("import net.sf.json.processors.JsonValueProcessor;").append("\n")
		.append("").append("\n")
		.append("/**").append("\n")
		.append(" * ").append("\n")
		.append(" * <pre>").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * @Copyright sf-express.").append("\n")
		.append(" * All rights reserved.").append("\n")
		.append(" * @Title:JsonDateValueProcessor.java").append("\n")
		.append(" * @Package com.sf.module."+Common.MODULE_NAME+".excel.processors ").append("\n")
		.append(" * @Description: Json值格式化处理方法").append("\n")
		.append(" * @author 613413").append("\n")
		.append(" * HISTORY").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" *  ID     DATE          PERSON          REASON").append("\n")
		.append(" *  1      2014-5-23     613413         创建").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * </pre>").append("\n")
		.append(" */").append("\n")
		.append("public class JsonDateValueProcessor implements JsonValueProcessor {").append("\n")
		.append("\t").append("  ").append("\n")
		.append("    private String format = \"yyyy-MM-dd HH:mm:ss\";").append("\n")
		.append("  ").append("\n")
		.append("    public JsonDateValueProcessor() {").append("\n")
		.append("  ").append("\n")
		.append("    }").append("\n")
		.append("  ").append("\n")
		.append("    public JsonDateValueProcessor(String format) {").append("\n")
		.append("        this.format = format;").append("\n")
		.append("    }").append("\n")
		.append("  ").append("\n")
		.append("    public Object processArrayValue(Object value, JsonConfig jsonConfig) {").append("\n")
		.append("        String[] obj = {};").append("\n")
		.append("        if (value instanceof Date[]) {").append("\n")
		.append("            SimpleDateFormat sf = new SimpleDateFormat(format);").append("\n")
		.append("            Date[] dates = (Date[]) value;").append("\n")
		.append("            obj = new String[dates.length];").append("\n")
		.append("            for (int i = 0; i < dates.length; i++) {").append("\n")
		.append("                obj[i] = sf.format(dates[i]);").append("\n")
		.append("            }").append("\n")
		.append("        }").append("\n")
		.append("        return obj;").append("\n")
		.append("    }").append("\n")
		.append("  ").append("\n")
		.append("    public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {").append("\n")
		.append("        if (value instanceof Date) {").append("\n")
		.append("            String str = new SimpleDateFormat(format).format((Date) value);").append("\n")
		.append("            return str;").append("\n")
		.append("        }").append("\n")
		.append("        return value == null ? null : value.toString();").append("\n")
		.append("    }").append("\n")
		.append("  ").append("\n")
		.append("    public String getFormat() {").append("\n")
		.append("        return format;").append("\n")
		.append("    }").append("\n")
		.append("  ").append("\n")
		.append("    public void setFormat(String format) {").append("\n")
		.append("        this.format = format;").append("\n")
		.append("    }").append("\n")
		.append("}").append("\n");

		File file = new File(Common.SAVE_PATH+File.separator+"excel"+File.separator+"processors");
		if(!file.exists()){
			file.mkdirs();
		}
		Common.write(new File(file,"JsonDateValueProcessor.java"), buff.toString());
		
		System.out.println("JsonDateValueProcessor.java 已生成.....");
	}
	
	private static void create_processor_Float(){
		buff = new StringBuffer();
		buff.append("package com.sf.module."+Common.MODULE_NAME+".excel.processors;").append("\n")
		.append("").append("\n")
		.append("import java.math.RoundingMode;").append("\n")
		.append("import java.text.NumberFormat;").append("\n")
		.append("import java.util.Locale;").append("\n")
		.append("").append("\n")
		.append("import net.sf.json.JsonConfig;").append("\n")
		.append("import net.sf.json.processors.JsonValueProcessor;").append("\n")
		.append("/**").append("\n")
		.append(" * ").append("\n")
		.append(" * <pre>").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * @Copyright sf-express.").append("\n")
		.append(" * All rights reserved.").append("\n")
		.append(" * @Title:JsonFloatValueProcessor.java").append("\n")
		.append(" * @Package com.sf.module."+Common.MODULE_NAME+".excel.processors ").append("\n")
		.append(" * @Description: 这里用一句话描述这个类的作用").append("\n")
		.append(" * @author 613413").append("\n")
		.append(" * HISTORY").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" *  ID     DATE          PERSON          REASON").append("\n")
		.append(" *  1      2014-6-20     613413         创建").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * </pre>").append("\n")
		.append(" */").append("\n")
		.append("public class JsonFloatValueProcessor implements JsonValueProcessor {").append("\n")
		.append("").append("\n")
		.append("\t").append("public JsonFloatValueProcessor() { }").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 处理数组类型").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public Object processArrayValue(Object value, JsonConfig jsonConfig) {").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("if (value instanceof float[]) {").append("\n")
		.append("\t\t\t").append("").append("\n")
		.append("\t\t\t").append("String[] obj = {};").append("\n")
		.append("\t\t\t").append("").append("\n")
		.append("\t\t\t").append("float[] nums = (float[]) value;").append("\n")
		.append("\t\t\t").append("").append("\n")
		.append("\t\t\t").append("for (int i = 0; i < nums.length; i++) {").append("\n")
		.append("\t\t\t\t").append("obj[i] = roundHalfUp(nums[i], 3);").append("\n")
		.append("\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("").append("\n")
		.append("\t\t\t").append("return obj;").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("return value;").append("\n")
		.append("\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 处理单个对象").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("if (value instanceof Float) {").append("\n")
		.append("\t\t\t").append("return roundHalfUp((Float)value, 3);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("return value;").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("     * 四舍五入。").append("\n")
		.append("     * ").append("\n")
		.append("     * @param number 数值").append("\n")
		.append("     * @return 舍入后的数值").append("\n")
		.append("     * @see java.text.RoundingMode.HALF_UP").append("\n")
		.append("     */").append("\n")
		.append("    public String roundHalfUp(double number, int frac) {").append("\n")
		.append("\t").append("    NumberFormat fmt = NumberFormat.getInstance(Locale.CHINA);").append("\n")
		.append("\t").append("    ").append("\n")
		.append("\t").append("    fmt.setMaximumFractionDigits(frac);").append("\n")
		.append("\t").append("    fmt.setRoundingMode(RoundingMode.HALF_UP);").append("\n")
		.append("\t").append("    ").append("\n")
		.append("\t").append("    return fmt.format(number);").append("\n")
		.append("    }").append("\n")
		.append("}").append("\n");

		File file = new File(Common.SAVE_PATH+File.separator+"excel"+File.separator+"processors");
		if(!file.exists()){
			file.mkdirs();
		}
		Common.write(new File(file,"JsonFloatValueProcessor.java"), buff.toString());
		
		System.out.println("JsonFloatValueProcessor.java 已生成.....");
	}
	
	private static void create_processor_Number(){
		buff = new StringBuffer();
		buff.append("package com.sf.module."+Common.MODULE_NAME+".excel.processors;").append("\n")
		.append("").append("\n")
		.append("import net.sf.json.JsonConfig;").append("\n")
		.append("import net.sf.json.processors.JsonValueProcessor;").append("\n")
		.append("").append("\n")
		.append("/**").append("\n")
		.append(" * <pre>").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * @Copyright sf-express.").append("\n")
		.append(" * All rights reserved.").append("\n")
		.append(" * @Title:JsonNuberValueProcessor.java").append("\n")
		.append(" * @Package com.sf.module."+Common.MODULE_NAME+".excel.processors ").append("\n")
		.append(" * @Description: 这里用一句话描述这个类的作用").append("\n")
		.append(" * @author 613413").append("\n")
		.append(" * HISTORY").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" *  ID     DATE          PERSON          REASON").append("\n")
		.append(" *  1      2014-6-20     613413         创建").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * </pre>").append("\n")
		.append(" */").append("\n")
		.append("public class JsonNumberValueProcessor implements JsonValueProcessor {     ").append("\n")
		.append("").append("\n")
		.append("").append("\n")
		.append("    public JsonNumberValueProcessor() {").append("\n")
		.append("  ").append("\n")
		.append("    }").append("\n")
		.append("\t").append("@Override").append("\n")
		.append("\t").append("public Object processArrayValue(Object arg0, JsonConfig arg1) {").append("\n")
		.append("        String[] obj = {};").append("\n")
		.append("        return obj;").append("\n")
		.append("\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t").append("@Override").append("\n")
		.append("\t").append("public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {").append("\n")
		.append("\t").append("        return value == null ? \"\" : value;").append("\n")
		.append("\t").append("}     ").append("\n")
		.append("}    ").append("\n");

		File file = new File(Common.SAVE_PATH+File.separator+"excel"+File.separator+"processors");
		if(!file.exists()){
			file.mkdirs();
		}
		Common.write(new File(file,"JsonNumberValueProcessor.java"), buff.toString());
		
		System.out.println("JsonNumberValueProcessor.java 已生成.....");
	}
	
	private static void create_PoiUtil(){
		buff = new StringBuffer();
		buff.append("package com.sf.module."+Common.MODULE_NAME+".util;").append("\n")
		.append("").append("\n")
		.append("").append("\n")
		.append("import java.io.File;").append("\n")
		.append("import java.io.FileOutputStream;").append("\n")
		.append("import java.io.IOException;").append("\n")
		.append("import java.io.InputStream;").append("\n")
		.append("import java.text.SimpleDateFormat;").append("\n")
		.append("import java.util.ArrayList;").append("\n")
		.append("import java.util.Date;").append("\n")
		.append("import java.util.Iterator;").append("\n")
		.append("import java.util.List;").append("\n")
		.append("").append("\n")
		.append("import javax.xml.parsers.ParserConfigurationException;").append("\n")
		.append("").append("\n")
		.append("import net.sf.json.JSONArray;").append("\n")
		.append("import net.sf.json.JSONObject;").append("\n")
		.append("import net.sf.json.JsonConfig;").append("\n")
		.append("").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFCell;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFCellStyle;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFDateUtil;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFFont;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFRichTextString;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFRow;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFSheet;").append("\n")
		.append("import org.apache.poi.hssf.usermodel.HSSFWorkbook;").append("\n")
		.append("import org.apache.poi.hssf.util.HSSFColor.GREY_40_PERCENT;").append("\n")
		.append("import org.apache.poi.ss.usermodel.Cell;").append("\n")
		.append("import org.apache.poi.ss.usermodel.CellStyle;").append("\n")
		.append("import org.apache.poi.ss.util.CellRangeAddress;").append("\n")
		.append("import org.xml.sax.SAXException;").append("\n")
		.append("").append("\n")
		.append("import com.sf.module.gswmgmt.excel.ExcelColumn;").append("\n")
		.append("import com.sf.module.gswmgmt.excel.ExcelHeaderConfig;").append("\n")
		.append("import com.sf.module.gswmgmt.excel.ExcelNameConfig;").append("\n")
		.append("import com.sf.module.gswmgmt.excel.processors.JsonDateValueProcessor;").append("\n")
		.append("import com.sf.module.gswmgmt.excel.processors.JsonNumberValueProcessor;").append("\n")
		.append("").append("\n")
		.append("/**").append("\n")
		.append(" * <pre>").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * @Copyright sf-express.").append("\n")
		.append(" * All rights reserved.").append("\n")
		.append(" * @Title:PoiUtil.java").append("\n")
		.append(" * @Package com.sf.module."+Common.MODULE_NAME+".util ").append("\n")
		.append(" * @Description: Poi处理工具").append("\n")
		.append(" * @author 613413").append("\n")
		.append(" * HISTORY").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" *  ID     DATE          PERSON          REASON").append("\n")
		.append(" *  1      2014-5-23     613413         创建").append("\n")
		.append(" * *********************************************").append("\n")
		.append(" * </pre>").append("\n")
		.append(" */").append("\n")
		.append("public class PoiUtil {").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * @Title: 通用导出(excelCode, list)").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static String exportExcel(String excelCode, List<?> list) throws Exception {").append("\n")
		.append("\t\t").append("return PoiUtil.exportExcel(excelCode, list, null, null, 1, false);").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * @Title: 通用导出(excelCode, list, suffix, hiddenColumn)").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static String exportExcel(String excelCode,List<?> list, ").append("\n")
		.append("\t\t\t").append("String suffix,String hiddenColumn) throws Exception {").append("\n")
		.append("\t\t").append("return PoiUtil.exportExcel(excelCode, list, suffix, hiddenColumn, 1, false);").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * @Title: 通用导出(excelCode, list, rows)").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static String exportExcel(String excelCode,List<?> list,").append("\n")
		.append("\t\t\t").append("int rows) throws Exception {").append("\n")
		.append("\t\t").append("return PoiUtil.exportExcel(excelCode, list, null, null, rows, false);").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * @Title: 通用导出(excelCode, list, suffix, hiddenColumn, rows)").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static String exportExcel(String excelCode, List<?> list, ").append("\n")
		.append("\t\t\t").append("String suffix,String hiddenColumn, int rows) throws Exception {").append("\n")
		.append("\t\t").append("return PoiUtil.exportExcel(excelCode, list, suffix, hiddenColumn, rows, false);").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: exportExcel ").append("\n")
		.append("\t").append(" * @Description: 通用导出方法").append("\n")
		.append("\t").append(" * @param excelCodeExcel的Code名称").append("\n")
		.append("\t").append(" * @param list数据List").append("\n")
		.append("\t").append(" * @param suffixExcel中文名对应Code").append("\n")
		.append("\t").append(" * @param hiddenColumn隐藏字段序列 \"|1|2|3|\"").append("\n")
		.append("\t").append(" * @param rows表头占用行").append("\n")
		.append("\t").append(" * @param xmlflg").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" * @throws Exception").append("\n")
		.append("\t").append(" * @return String").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-6-17").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static String exportExcel(String excelCode,List<?> list,").append("\n")
		.append("\t\t\t").append("String suffix, String hiddenColumn, int rows , boolean xmlflg) throws Exception {").append("\n")
		.append("\t\t").append("String excelName = \"导出文档\";").append("\n")
		.append("\t\t").append("if(suffix!=null && suffix.length()>0){").append("\n")
		.append("\t\t\t").append("excelName = ExcelNameConfig.getExcelName(excelCode, suffix);").append("\n")
		.append("\t\t").append("}else{").append("\n")
		.append("\t\t\t").append("excelName = ExcelNameConfig.getExcelName(excelCode, ExcelNameConfig.LabelType.Name);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("// 写入的文件流").append("\n")
		.append("\t\t").append("FileOutputStream fos = null;").append("\n")
		.append("\t\t").append("InputStream fis = null;").append("\n")
		.append("\t\t").append("try {").append("\n")
		.append("\t\t\t").append("HSSFWorkbook workbook = PoiUtil.generateWorkbook(excelCode, list, suffix, hiddenColumn, rows, xmlflg);").append("\n")
		.append("\t\t\t").append("// 写文件").append("\n")
		.append("\t\t\t").append("File file = CommonUtil.getExcelSavePath(excelName+\".xls\");").append("\n")
		.append("\t\t\t").append("fos = new FileOutputStream(file);").append("\n")
		.append("\t\t\t").append("workbook.write(fos);").append("\n")
		.append("\t\t\t").append("return file.getName();").append("\n")
		.append("\t\t").append("} catch (Exception e) {").append("\n")
		.append("\t\t\t").append("throw e;").append("\n")
		.append("\t\t").append("} finally {").append("\n")
		.append("\t\t\t").append("if (fos != null) {").append("\n")
		.append("\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t").append("fos.close();").append("\n")
		.append("\t\t\t\t").append("} catch (Exception e2) {").append("\n")
		.append("\t\t\t\t\t").append("throw e2;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("if (fis != null) {").append("\n")
		.append("\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t").append("fis.close();").append("\n")
		.append("\t\t\t\t").append("} catch (Exception e2) {").append("\n")
		.append("\t\t\t\t\t").append("throw e2;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("}").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: generateWorkbook ").append("\n")
		.append("\t").append(" * @Description: 导出Excel处理方法").append("\n")
		.append("\t").append(" * @param excelCode Excel对应英文名").append("\n")
		.append("\t").append(" * @param list 数据List").append("\n")
		.append("\t").append(" * @param hiddenColumn ").append("\n")
		.append("\t").append(" * @param displayColumn2 ").append("\n")
		.append("\t").append(" * @param rows 表头占用行数").append("\n")
		.append("\t").append(" * @param xmlflg ").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" * @throws SAXException").append("\n")
		.append("\t").append(" * @throws IOException").append("\n")
		.append("\t").append(" * @throws ParserConfigurationException").append("\n")
		.append("\t").append(" * @return HSSFWorkbook").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-27").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static HSSFWorkbook generateWorkbook(String excelCode, List<?> list, ").append("\n")
		.append("\t\t\t").append("String suffix, String hiddenColumn, int rows, boolean xmlflg) throws IOException{").append("\n")
		.append("\t\t").append("ArrayList<ExcelColumn> extColumnList = new ArrayList<ExcelColumn>();").append("\n")
		.append("\t\t").append("ExcelColumn gridcolumn = null;").append("\n")
		.append("\t\t").append("/** 两种获取表头和字段对应关系的方式  **/").append("\n")
		.append("\t\t").append("if(xmlflg){").append("\n")
		.append("\t\t\t").append("/** 第一种：XML 获取表头 **/").append("\n")
		.append("\t\t\t").append("//extColumnList = JdomUtil.parseXml(excelCode+\".xml\");").append("\n")
		.append("\t\t").append("}else{").append("\n")
		.append("\t\t\t").append("/** 第二种：ExcelType 获取表头 **/").append("\n")
		.append("\t\t\t").append("extColumnList = ExcelHeaderConfig.getExcelHeaderList(excelCode, hiddenColumn);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("//取得Excel对应中文名").append("\n")
		.append("\t\t").append("String excelName = \"导出文档\";").append("\n")
		.append("\t\t").append("String tplName = ExcelNameConfig.getExcelName(excelCode, ExcelNameConfig.LabelType.Name);;").append("\n")
		.append("\t\t").append("if(suffix!=null && suffix.length()>0){").append("\n")
		.append("\t\t\t").append("excelName = ExcelNameConfig.getExcelName(excelCode, suffix);").append("\n")
		.append("\t\t").append("}else{").append("\n")
		.append("\t\t\t").append("excelName = ExcelNameConfig.getExcelName(excelCode, ExcelNameConfig.LabelType.Name);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("//数据list转json").append("\n")
		.append("\t\t").append("JSONArray jsonArray = PoiUtil.getJSONArrayForList(list);").append("\n")
		.append("").append("\n")
		.append("\t\t").append("HSSFWorkbook workbook = new HSSFWorkbook();").append("\n")
		.append("\t\t").append("//字体").append("\n")
		.append("\t\t").append("//加粗字体").append("\n")
		.append("\t\t").append("HSSFFont boldFont = workbook.createFont();").append("\n")
		.append("\t\t").append("boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);").append("\n")
		.append("\t\t").append("boldFont.setFontName(\"宋体\");").append("\n")
		.append("\t\t").append("//普通字体").append("\n")
		.append("\t\t").append("HSSFFont normalFont = workbook.createFont();").append("\n")
		.append("\t\t").append("normalFont.setFontName(\"宋体\");").append("\n")
		.append("\t\t").append("normalFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);").append("\n")
		.append("").append("\n")
		.append("\t\t").append("//单元格样式").append("\n")
		.append("\t\t").append("//粗体单元格 - 居中").append("\n")
		.append("\t\t").append("HSSFCellStyle boldStyle = workbook.createCellStyle();").append("\n")
		.append("\t\t").append("boldStyle.setFont(boldFont);").append("\n")
		.append("\t\t").append("boldStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);").append("\n")
		.append("\t\t").append("boldStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);").append("\n")
		.append("\t\t").append("boldStyle.setWrapText(true); //单元格文本自动换行").append("\n")
		.append("\t\t").append("boldStyle.setBorderTop((short)1);").append("\n")
		.append("\t\t").append("boldStyle.setBorderLeft((short)1);").append("\n")
		.append("\t\t").append("boldStyle.setBorderRight((short)1);").append("\n")
		.append("\t\t").append("boldStyle.setBorderBottom((short)1);").append("\n")
		.append("\t\t").append("boldStyle.setFillForegroundColor(GREY_40_PERCENT.index);").append("\n")
		.append("\t\t").append("boldStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);").append("\n")
		.append("").append("\n")
		.append("\t\t").append("//普通单元格 - 居中").append("\n")
		.append("\t\t").append("HSSFCellStyle normalStyle = workbook.createCellStyle();").append("\n")
		.append("\t\t").append("normalStyle.setFont(normalFont);").append("\n")
		.append("\t\t").append("normalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);").append("\n")
		.append("\t\t").append("normalStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);").append("\n")
		.append("\t\t").append("normalStyle.setWrapText(true); //单元格文本自动换行").append("\n")
		.append("\t\t").append("normalStyle.setBorderTop((short)1);").append("\n")
		.append("\t\t").append("normalStyle.setBorderLeft((short)1);").append("\n")
		.append("\t\t").append("normalStyle.setBorderRight((short)1);").append("\n")
		.append("\t\t").append("normalStyle.setBorderBottom((short)1);").append("\n")
		.append("").append("\n")
		.append("").append("\n")
		.append("\t\t").append("HSSFRow row = null;").append("\n")
		.append("\t\t\t\t").append("HSSFCell cell = null;").append("\n")
		.append("\t\t").append("int colNum = 0; //列编号").append("\n")
		.append("\t\t\t").append("int rowNum = 0;").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("JSONObject jsonObject = null;").append("\n")
		.append("\t\t").append("String cellval = \"\";").append("\n")
		.append("\t\t").append("String dataindex = \"\";").append("\n")
		.append("\t\t").append("//导出文件sheet").append("\n")
		.append("\t\t").append("HSSFSheet sheet = null;").append("\n")
		.append("\t\t").append("//模板文件").append("\n")
		.append("\t\t").append("InputStream fis = null;").append("\n")
		.append("\t\t").append("HSSFWorkbook wb = null;").append("\n")
		.append("\t\t").append("HSSFSheet sheettemp = null;").append("\n")
		.append("\t\t").append("//如果表头大于两行，为多表头结构，则读取模板复制表头").append("\n")
		.append("\t\t").append("if(rows > 1){").append("\n")
		.append("\t\t\t").append("fis = CommonUtil.getDownloadStream(tplName+\".xls\");").append("\n")
		.append("\t\t\t").append("wb = new HSSFWorkbook(fis);").append("\n")
		.append("\t\t\t\t").append("sheettemp = wb.getSheetAt(0);//获取第一个sheet页").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("////=====================工作表开始================////").append("\n")
		.append("\t\t").append("sheet = workbook.createSheet(excelName);").append("\n")
		.append("").append("\n")
		.append("\t\t\t").append("//  table head row 1").append("\n")
		.append("\t\t").append("rowNum = 0;").append("\n")
		.append("\t\t").append("row = sheet.createRow(rowNum);").append("\n")
		.append("\t\t").append("row.setHeightInPoints((float) 30); //设置行高，以点为单位").append("\n")
		.append("\t\t").append("////=====================表头开始=====================////").append("\n")
		.append("\t\t").append("if(rows == 1){").append("\n")
		.append("\t\t\t").append("colNum = 0;").append("\n")
		.append("\t\t\t").append("for (int k = 0; extColumnList!=null && k < extColumnList.size();k++){").append("\n")
		.append("\t\t\t\t").append("gridcolumn = (ExcelColumn)extColumnList.get(k);").append("\n")
		.append("\t\t\t\t").append("if(gridcolumn.getDisplay()!=null && gridcolumn.getDisplay().equals(\"false\")){").append("\n")
		.append("\t\t\t\t\t").append("continue;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t").append("Short columnWidth = 10;").append("\n")
		.append("\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t").append("columnWidth = Short.parseShort(gridcolumn.getWidth());").append("\n")
		.append("\t\t\t\t").append("} catch (Exception e) {").append("\n")
		.append("\t\t\t\t\t").append("columnWidth = 10;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t").append("sheet.setColumnWidth(colNum, (columnWidth * 256)); //设置列宽，以一个ASCII字符的1/256宽度为单位").append("\n")
		.append("\t\t\t\t").append("cell = row.createCell(colNum); //创建单元格").append("\n")
		.append("\t\t\t\t").append("cell.setCellStyle(boldStyle); //设置单元格格式").append("\n")
		.append("\t\t\t\t").append("//cell.setEncoding(HSSFCell.ENCODING_UTF_16); //设置编码，使不会因为截除中文高位而出现乱码").append("\n")
		.append("\t\t\t\t").append("cell.setCellValue(new HSSFRichTextString(gridcolumn.getName())); //设置单元格的值").append("\n")
		.append("\t\t\t\t\t\t\t").append("colNum++;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t").append("}else{").append("\n")
		.append("\t\t\t").append("//如果表头大于两行，为多表头结构，则读取模板复制表头").append("\n")
		.append("\t\t\t").append("copySheet(workbook, sheettemp, sheet, true);").append("\n")
		.append("\t\t\t").append("colNum = 0;").append("\n")
		.append("\t\t\t").append("for (int k = 0; extColumnList!=null && k < extColumnList.size();k++){").append("\n")
		.append("\t\t\t\t").append("gridcolumn = (ExcelColumn)extColumnList.get(k);").append("\n")
		.append("\t\t\t\t").append("if(gridcolumn.getDisplay()!=null && gridcolumn.getDisplay().equals(\"false\")){").append("\n")
		.append("\t\t\t\t\t").append("sheet.setColumnHidden(colNum, true);").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t").append("Short columnWidth = 10;").append("\n")
		.append("\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t").append("columnWidth = Short.parseShort(gridcolumn.getWidth());").append("\n")
		.append("\t\t\t\t").append("} catch (Exception e) {").append("\n")
		.append("\t\t\t\t\t").append("columnWidth = 10;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t").append("sheet.setColumnWidth(colNum, (columnWidth * 256)); //设置列宽，以一个ASCII字符的1/256宽度为单位").append("\n")
		.append("\t\t\t\t\t\t\t").append("colNum++;").append("\n")
		.append("\t\t\t").append("}").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("////=====================表头结束=====================////").append("\n")
		.append("").append("\n")
		.append("\t\t").append("////=====================数据开始=====================////").append("\n")
		.append("\t\t").append("rowNum = rows;").append("\n")
		.append("\t\t").append("row = null;").append("\n")
		.append("\t\t").append("cell = null;").append("\n")
		.append("\t\t").append("if( jsonArray!=null && !jsonArray.toString().equalsIgnoreCase(\"[null]\")){").append("\n")
		.append("\t\t\t").append("for (int i = 0; i < jsonArray.size(); i++) {").append("\n")
		.append("\t\t\t\t").append("if( i!=0 && i % 50000 == 0){").append("\n")
		.append("\t\t\t\t").append("////=====================工作表开始================////").append("\n")
		.append("\t\t\t\t\t").append("sheet = workbook.createSheet(excelName+String.valueOf(i / 50000+1));").append("\n")
		.append("\t\t\t\t\t").append("").append("\n")
		.append("\t\t\t\t\t\t").append("//  table head row 1").append("\n")
		.append("\t\t\t\t\t").append("rowNum = 0;").append("\n")
		.append("\t\t\t\t\t").append("row = sheet.createRow(rowNum);").append("\n")
		.append("\t\t\t\t\t").append("row.setHeightInPoints((float) 30); //设置行高，以点为单位").append("\n")
		.append("\t\t\t\t\t").append("////=====================表头开始=====================////").append("\n")
		.append("\t\t\t\t\t").append("if(rows == 1){").append("\n")
		.append("\t\t\t\t\t\t").append("colNum = 0;").append("\n")
		.append("\t\t\t\t\t\t").append("for (int k = 0; extColumnList!=null && k < extColumnList.size();k++){").append("\n")
		.append("\t\t\t\t\t\t\t").append("gridcolumn = (ExcelColumn)extColumnList.get(k);").append("\n")
		.append("\t\t\t\t\t\t\t").append("if(gridcolumn.getDisplay()!=null && gridcolumn.getDisplay().equals(\"false\")){").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("continue;").append("\n")
		.append("\t\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t\t\t").append("Short columnWidth = 10;").append("\n")
		.append("\t\t\t\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("columnWidth = Short.parseShort(gridcolumn.getWidth());").append("\n")
		.append("\t\t\t\t\t\t\t").append("} catch (Exception e) {").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("columnWidth = 10;").append("\n")
		.append("\t\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t\t\t").append("sheet.setColumnWidth(colNum, (columnWidth * 256)); //设置列宽，以一个ASCII字符的1/256宽度为单位").append("\n")
		.append("\t\t\t\t\t\t\t").append("cell = row.createCell(colNum); //创建单元格").append("\n")
		.append("\t\t\t\t\t\t\t").append("cell.setCellStyle(boldStyle); //设置单元格格式").append("\n")
		.append("\t\t\t\t\t\t\t").append("//cell.setEncoding(HSSFCell.ENCODING_UTF_16); //设置编码，使不会因为截除中文高位而出现乱码").append("\n")
		.append("\t\t\t\t\t\t\t").append("cell.setCellValue(new HSSFRichTextString(gridcolumn.getName())); //设置单元格的值").append("\n")
		.append("\t\t\t\t\t\t\t\t\t\t").append("colNum++;").append("\n")
		.append("\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t").append("}else{").append("\n")
		.append("\t\t\t\t\t\t").append("copySheet(workbook, sheettemp, sheet, true);").append("\n")
		.append("\t\t\t\t\t\t").append("colNum = 0;").append("\n")
		.append("\t\t\t\t\t\t").append("for (int k = 0; extColumnList!=null && k < extColumnList.size();k++){").append("\n")
		.append("\t\t\t\t\t\t\t").append("gridcolumn = (ExcelColumn)extColumnList.get(k);").append("\n")
		.append("\t\t\t\t\t\t\t").append("if(gridcolumn.getDisplay()!=null && gridcolumn.getDisplay().equals(\"false\")){").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("sheet.setColumnHidden(colNum, true);").append("\n")
		.append("\t\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t\t\t").append("Short columnWidth = 10;").append("\n")
		.append("\t\t\t\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("columnWidth = Short.parseShort(gridcolumn.getWidth());").append("\n")
		.append("\t\t\t\t\t\t\t").append("} catch (Exception e) {").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("columnWidth = 10;").append("\n")
		.append("\t\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t\t\t").append("sheet.setColumnWidth(colNum, (columnWidth * 256)); //设置列宽，以一个ASCII字符的1/256宽度为单位").append("\n")
		.append("\t\t\t\t\t\t\t\t\t\t").append("colNum++;").append("\n")
		.append("\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t\t").append("").append("\n")
		.append("\t\t\t\t\t").append("////=====================表头结束=====================////").append("\n")
		.append("\t").append("").append("\n")
		.append("\t\t\t\t\t").append("////=====================数据开始=====================////").append("\n")
		.append("\t\t\t\t\t").append("rowNum = rows;").append("\n")
		.append("\t\t\t\t\t").append("row = null;").append("\n")
		.append("\t\t\t\t\t").append("cell = null;").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t\t").append("").append("\n")
		.append("\t\t\t\t").append("jsonObject = (JSONObject)jsonArray.get(i);").append("\n")
		.append("\t\t\t\t").append("colNum = 0;").append("\n")
		.append("\t\t\t\t").append("row = sheet.createRow(rowNum);").append("\n")
		.append("\t\t\t").append("    row.setHeightInPoints((float) 20);").append("\n")
		.append("\t\t\t").append("    for (int k = 0; extColumnList!=null && k < extColumnList.size();k++){").append("\n")
		.append("\t\t\t\t").append("    gridcolumn = (ExcelColumn)extColumnList.get(k);").append("\n")
		.append("\t\t\t\t").append("    if(rows == 1 && gridcolumn.getDisplay()!=null && gridcolumn.getDisplay().equals(\"false\")){").append("\n")
		.append("\t\t\t\t\t").append("    continue;").append("\n")
		.append("\t\t\t\t").append("    }").append("\n")
		.append("\t\t\t\t").append("    cell = row.createCell(colNum); ").append("\n")
		.append("\t\t\t").append("        cell.setCellStyle(normalStyle); //设置单元格格式").append("\n")
		.append("\t\t\t").append("        dataindex = gridcolumn.getCode();").append("\n")
		.append("\t\t\t").append("        cellval = (String)jsonObject.getString(dataindex);").append("\n")
		.append("\t\t\t").append("        if(gridcolumn.getTimeFormat()!= null ").append("\n")
		.append("\t\t\t\t\t").append("        && gridcolumn.getTimeFormat().length()>0").append("\n")
		.append("\t\t\t\t\t").append("        && cellval != null && !cellval.equalsIgnoreCase(\"null\")){").append("\n")
		.append("\t\t\t\t\t\t").append("SimpleDateFormat format = new SimpleDateFormat(gridcolumn.getTimeFormat());").append("\n")
		.append("\t\t\t\t\t\t").append("Date date = null;").append("\n")
		.append("\t\t\t\t\t\t").append("try {").append("\n")
		.append("\t\t\t\t\t\t\t").append("date = format.parse(cellval);").append("\n")
		.append("\t\t\t\t\t\t\t").append("cellval = format.format(date);").append("\n")
		.append("\t\t\t\t\t\t").append("}catch (Exception e) {").append("\n")
		.append("\t\t\t\t\t\t\t").append("e.printStackTrace();").append("\n")
		.append("\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("        }").append("\n")
		.append("\t\t\t").append("        if(CommonUtil.isNumeric(cellval)){").append("\n")
		.append("\t\t\t\t").append("        //强转数值型，如果强转失败就按String型写入").append("\n")
		.append("\t\t\t\t").append("        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);").append("\n")
		.append("\t\t\t\t").append("        try {").append("\n")
		.append("\t\t\t\t\t").append("        cell.setCellValue(Double.parseDouble(cellval));").append("\n")
		.append("\t\t\t\t\t\t").append("} catch (Exception e) {").append("\n")
		.append("\t\t\t\t\t").append("        cell.setCellValue(new HSSFRichTextString(cellval==null||cellval.equalsIgnoreCase(\"null\")?\"\":cellval));").append("\n")
		.append("\t\t\t\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("        }else{").append("\n")
		.append("\t\t\t\t").append("        cell.setCellValue(new HSSFRichTextString(cellval==null||cellval.equalsIgnoreCase(\"null\")?\"\":cellval));").append("\n")
		.append("\t\t\t").append("        }").append("\n")
		.append("\t\t\t\t\t\t\t\t").append("colNum++;    ").append("\n")
		.append("\t\t\t").append("    }").append("\n")
		.append("\t\t\t").append("    rowNum++;").append("\n")
		.append("\t\t\t").append("}").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("////=====================数据结束=====================////").append("\n")
		.append("\t\t").append("return workbook;").append("\n")
		.append("\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: getJSONArrayForList ").append("\n")
		.append("\t").append(" * @Description: List转JSON").append("\n")
		.append("\t").append(" * @param list").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" * @return JSONArray").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-27").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static JSONArray getJSONArrayForList(List<?> list){").append("\n")
		.append("\t\t").append("JSONArray jsonArray = null;").append("\n")
		.append("\t\t").append("JsonConfig jsonConfig = new JsonConfig();").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,new JsonDateValueProcessor(\"yyyy-MM-dd hh:mm:ss\"));").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(java.util.Date.class,new JsonDateValueProcessor(\"yyyy-MM-dd hh:mm:ss\"));").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(Long.class,new JsonNumberValueProcessor());").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(Integer.class,new JsonNumberValueProcessor());").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(Double.class,new JsonNumberValueProcessor());").append("\n")
		.append("\t\t").append("jsonArray = JSONArray.fromObject(list, jsonConfig);").append("\n")
		.append("\t\t").append("return jsonArray;").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: getListForJSONArray ").append("\n")
		.append("\t").append(" * @Description: JSON 转 List").append("\n")
		.append("\t").append(" * @param jsonArray").append("\n")
		.append("\t").append(" * @param o").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" * @return List<?>").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-6-18").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static List<?> getListForJSONArray(JSONArray jsonArray,Object o){").append("\n")
		.append("\t\t").append("List<?> list = null;").append("\n")
		.append("\t\t").append("JsonConfig jsonConfig = new JsonConfig();").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,new JsonDateValueProcessor(\"yyyy-MM-dd hh:mm:ss\"));").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(java.util.Date.class,new JsonDateValueProcessor(\"yyyy-MM-dd hh:mm:ss\"));").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(Long.class,new JsonNumberValueProcessor());").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(Integer.class,new JsonNumberValueProcessor());").append("\n")
		.append("\t\t").append("jsonConfig.registerJsonValueProcessor(Double.class,new JsonNumberValueProcessor());").append("\n")
		.append("\t\t").append("list = JSONArray.toList(jsonArray, o, jsonConfig);").append("\n")
		.append("\t\t").append("return list;").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: copyCellStyle ").append("\n")
		.append("\t").append(" * @Description: 复制单元格样式").append("\n")
		.append("\t").append(" * @param fromStyle").append("\n")
		.append("\t").append(" * @param toStyle").append("\n")
		.append("\t").append(" * @return void").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-27").append("\n")
		.append("\t").append(" * @throws").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static void copyCellStyle(CellStyle cellStyle,").append("\n")
		.append("\t\t\t").append("HSSFCellStyle toStyle) {").append("\n")
		.append("\t\t").append("toStyle.setAlignment(cellStyle.getAlignment());").append("\n")
		.append("\t\t").append("//边框和边框颜色").append("\n")
		.append("\t\t").append("toStyle.setBorderBottom(cellStyle.getBorderBottom());").append("\n")
		.append("\t\t").append("toStyle.setBorderLeft(cellStyle.getBorderLeft());").append("\n")
		.append("\t\t").append("toStyle.setBorderRight(cellStyle.getBorderRight());").append("\n")
		.append("\t\t").append("toStyle.setBorderTop(cellStyle.getBorderTop());").append("\n")
		.append("\t\t").append("toStyle.setTopBorderColor(cellStyle.getTopBorderColor());").append("\n")
		.append("\t\t").append("toStyle.setBottomBorderColor(cellStyle.getBottomBorderColor());").append("\n")
		.append("\t\t").append("toStyle.setRightBorderColor(cellStyle.getRightBorderColor());").append("\n")
		.append("\t\t").append("toStyle.setLeftBorderColor(cellStyle.getLeftBorderColor());").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("//背景和前景").append("\n")
		.append("\t\t").append("toStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());").append("\n")
		.append("\t\t").append("toStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t\t").append("toStyle.setDataFormat(cellStyle.getDataFormat());").append("\n")
		.append("\t\t").append("toStyle.setFillPattern(cellStyle.getFillPattern());").append("\n")
		.append("\t\t\t").append("//toStyle.setFont(fromStyle.getFont(null));").append("\n")
		.append("\t\t").append("toStyle.setHidden(cellStyle.getHidden());").append("\n")
		.append("\t\t").append("toStyle.setIndention(cellStyle.getIndention());//首行缩进").append("\n")
		.append("\t\t").append("toStyle.setLocked(cellStyle.getLocked());").append("\n")
		.append("\t\t").append("toStyle.setRotation(cellStyle.getRotation());//旋转").append("\n")
		.append("\t\t").append("toStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());").append("\n")
		.append("\t\t").append("toStyle.setWrapText(cellStyle.getWrapText());").append("\n")
		.append("\t\t").append("").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: copySheet ").append("\n")
		.append("\t").append(" * @Description: Sheet复制").append("\n")
		.append("\t").append(" * @param wb").append("\n")
		.append("\t").append(" * @param fromSheet").append("\n")
		.append("\t").append(" * @param toSheet").append("\n")
		.append("\t").append(" * @param copyValueFlag").append("\n")
		.append("\t").append(" * @return void").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-28").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static void copySheet(HSSFWorkbook wb,HSSFSheet fromSheet, HSSFSheet toSheet,").append("\n")
		.append("\t\t\t").append("boolean copyValueFlag) {").append("\n")
		.append("\t\t").append("//合并区域处理").append("\n")
		.append("\t\t").append("mergerRegion(fromSheet, toSheet);").append("\n")
		.append("\t\t").append("for (Iterator<?> rowIt = fromSheet.rowIterator(); rowIt.hasNext();) {").append("\n")
		.append("\t\t\t").append("HSSFRow tmpRow = (HSSFRow) rowIt.next();").append("\n")
		.append("\t\t\t").append("HSSFRow newRow = toSheet.createRow(tmpRow.getRowNum());").append("\n")
		.append("\t\t\t").append("//行复制").append("\n")
		.append("\t\t\t").append("copyRow(wb,tmpRow,newRow,copyValueFlag);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: copyRow ").append("\n")
		.append("\t").append(" * @Description: 行复制功能").append("\n")
		.append("\t").append(" * @param wb").append("\n")
		.append("\t").append(" * @param fromRow").append("\n")
		.append("\t").append(" * @param toRow").append("\n")
		.append("\t").append(" * @param copyValueFlag").append("\n")
		.append("\t").append(" * @return void").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-28").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static void copyRow(HSSFWorkbook wb,HSSFRow fromRow,HSSFRow toRow,boolean copyValueFlag){").append("\n")
		.append("\t\t").append("for (Iterator<?> cellIt = fromRow.cellIterator(); cellIt.hasNext();) {").append("\n")
		.append("\t\t\t").append("Cell tmpCell = (Cell) cellIt.next();").append("\n")
		.append("\t\t\t").append("Cell newCell = toRow.createCell(tmpCell.getColumnIndex());").append("\n")
		.append("\t\t\t").append("copyCell(wb,tmpCell, newCell, copyValueFlag);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: mergerRegion ").append("\n")
		.append("\t").append(" * @Description: 复制原有sheet的合并单元格到新创建的sheet").append("\n")
		.append("\t").append(" * @param fromSheet").append("\n")
		.append("\t").append(" * @param toSheet").append("\n")
		.append("\t").append(" * @return void").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-28").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static void mergerRegion(HSSFSheet fromSheet, HSSFSheet toSheet) {").append("\n")
		.append("\t").append("   int sheetMergerCount = fromSheet.getNumMergedRegions();").append("\n")
		.append("\t").append("   for (int i = 0; i < sheetMergerCount; i++) {").append("\n")
		.append("\t").append("    CellRangeAddress ca = fromSheet.getMergedRegion(i);").append("\n")
		.append("\t").append("    toSheet.addMergedRegion(ca);").append("\n")
		.append("\t").append("   }").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @Title: copyCell ").append("\n")
		.append("\t").append(" * @Description: 复制单元格").append("\n")
		.append("\t").append(" * @param wb").append("\n")
		.append("\t").append(" * @param tmpCell").append("\n")
		.append("\t").append(" * @param newCell").append("\n")
		.append("\t").append(" * @param copyValueFlag  true则连同cell的内容一起复制").append("\n")
		.append("\t").append(" * @return void").append("\n")
		.append("\t").append(" * @user 613413").append("\n")
		.append("\t").append(" * @date 2014-5-28").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static void copyCell(HSSFWorkbook wb,Cell tmpCell, Cell newCell,").append("\n")
		.append("\t\t\t").append("boolean copyValueFlag) {").append("\n")
		.append("\t\t").append("HSSFCellStyle newstyle=wb.createCellStyle();").append("\n")
		.append("\t\t").append("copyCellStyle(tmpCell.getCellStyle(), newstyle);").append("\n")
		.append("\t\t").append("//样式").append("\n")
		.append("\t\t").append("newCell.setCellStyle(newstyle);").append("\n")
		.append("\t\t").append("//评论").append("\n")
		.append("\t\t").append("if (tmpCell.getCellComment() != null) {").append("\n")
		.append("\t\t\t").append("newCell.setCellComment(tmpCell.getCellComment());").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("// 不同数据类型处理").append("\n")
		.append("\t\t").append("int srcCellType = tmpCell.getCellType();").append("\n")
		.append("\t\t").append("newCell.setCellType(srcCellType);").append("\n")
		.append("\t\t").append("if (copyValueFlag) {").append("\n")
		.append("\t\t\t").append("if (srcCellType == HSSFCell.CELL_TYPE_NUMERIC) {").append("\n")
		.append("\t\t\t\t").append("if (HSSFDateUtil.isCellDateFormatted(tmpCell)) {").append("\n")
		.append("\t\t\t\t\t").append("newCell.setCellValue(tmpCell.getDateCellValue());").append("\n")
		.append("\t\t\t\t").append("} else {").append("\n")
		.append("\t\t\t\t\t").append("newCell.setCellValue(tmpCell.getNumericCellValue());").append("\n")
		.append("\t\t\t\t").append("}").append("\n")
		.append("\t\t\t").append("} else if (srcCellType == HSSFCell.CELL_TYPE_STRING) {").append("\n")
		.append("\t\t\t\t").append("newCell.setCellValue(tmpCell.getRichStringCellValue());").append("\n")
		.append("\t\t\t").append("} else if (srcCellType == HSSFCell.CELL_TYPE_BLANK) {").append("\n")
		.append("\t\t\t\t").append("// nothing21").append("\n")
		.append("\t\t\t").append("} else if (srcCellType == HSSFCell.CELL_TYPE_BOOLEAN) {").append("\n")
		.append("\t\t\t\t").append("newCell.setCellValue(tmpCell.getBooleanCellValue());").append("\n")
		.append("\t\t\t").append("} else if (srcCellType == HSSFCell.CELL_TYPE_ERROR) {").append("\n")
		.append("\t\t\t\t").append("newCell.setCellErrorValue(tmpCell.getErrorCellValue());").append("\n")
		.append("\t\t\t").append("} else if (srcCellType == HSSFCell.CELL_TYPE_FORMULA) {").append("\n")
		.append("\t\t\t\t").append("newCell.setCellFormula(tmpCell.getCellFormula());").append("\n")
		.append("\t\t\t").append("} else { // nothing29").append("\n")
		.append("\t\t\t").append("}").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("").append("\n")
		.append("}").append("\n");

		File file = new File(Common.SAVE_PATH+File.separator+"util");
		if(!file.exists()){
			file.mkdirs();
		}
		Common.write(new File(file,"PoiUtil.java"), buff.toString());
		
		System.out.println("PoiUtil.java 已生成.....");
	}
	
	private static void create_CommonUtil(){
		buff = new StringBuffer();
		buff.append("package com.sf.module."+Common.MODULE_NAME+".util;").append("\n")
		.append("").append("\n")
		.append("import java.io.File;").append("\n")
		.append("import java.io.InputStream;").append("\n")
		.append("import java.util.UUID;").append("\n")
		.append("import java.util.regex.Pattern;").append("\n")
		.append("").append("\n")
		.append("import org.apache.struts2.ServletActionContext;").append("\n")
		.append("").append("\n")
		.append("import com.sf.framework.core.exception.BizException;").append("\n")
		.append("").append("\n")
		.append("public class CommonUtil {").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 临时文件夹path").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("private static String tempdirPath = null;").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 临时文件夹").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("private static final String EXCEL_CHILD_DIR = \"excel_tmp\";").append("\n")
		.append("\t").append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 获取servletTempdir 目录下 临时文件夹 注:非action请求无法获取").append("\n")
		.append("\t").append(" * ").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static File getTempdir() {").append("\n")
		.append("\t\t").append("File tempdir = null;").append("\n")
		.append("\t\t").append("if (tempdirPath == null) {").append("\n")
		.append("\t\t\t").append("tempdir = new File((File) ServletActionContext.getServletContext()").append("\n")
		.append("\t\t\t\t\t").append(".getAttribute(\"javax.servlet.context.tempdir\"),").append("\n")
		.append("\t\t\t\t\t").append("EXCEL_CHILD_DIR);").append("\n")
		.append("\t\t\t").append("tempdirPath = tempdir.getPath();").append("\n")
		.append("\t\t").append("} else {").append("\n")
		.append("\t\t\t").append("tempdir = new File(tempdirPath);").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t\t").append("if (!tempdir.exists()) {").append("\n")
		.append("\t\t\t").append("tempdir.mkdirs();").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t\t").append("return tempdir;").append("\n")
		.append("\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 获取唯一文件名").append("\n")
		.append("\t").append(" * @author 徐益森(sfhq217)").append("\n")
		.append("\t").append(" * @date 2012-09-03 ").append("\n")
		.append("\t").append(" * @param name原始文件名").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("private static String getUniqueFileName(String name) {").append("\n")
		.append("\t\t").append("return new StringBuffer(UUID.randomUUID().toString()).append(\"~\")").append("\n")
		.append("\t\t\t\t").append(".append(name).toString();").append("\n")
		.append("\t").append("}").append("\n")
		.append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 获取Excel保存文件").append("\n")
		.append("\t").append(" * @author 徐益森(sfhq217)").append("\n")
		.append("\t").append(" * @date 2012-09-03 ").append("\n")
		.append("\t").append(" * @param fileName 文件名").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static File getExcelSavePath(String fileName) {").append("\n")
		.append("\t\t").append("return new File(getTempdir(), getUniqueFileName(fileName));").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("").append("\n")
		.append("\t").append("/**").append("\n")
		.append("\t").append(" * 获取模板路径").append("\n")
		.append("\t").append(" * @return").append("\n")
		.append("\t").append(" */").append("\n")
		.append("\t").append("public static String getTemplatePath(String filename){").append("\n")
		.append("\t\t").append("String rootPath = CommonUtil.class.getPackage().getName() ;").append("\n")
		.append("\t\t").append("rootPath = rootPath.substring(0, rootPath.lastIndexOf(\".\")) ;").append("\n")
		.append("\t\t").append("rootPath = rootPath.replaceAll(\"\\.\", \"/\") ;").append("\n")
		.append("\t\t").append("return rootPath+\"/META-INF/tpl/\"+filename;").append("\n")
		.append("\t").append("}").append("\n")
		.append("\t").append("public static boolean isNumeric(String str){ ").append("\n")
		.append("\t\t").append("if(str==null || str.equals(\"\")){").append("\n")
		.append("\t\t\t").append("return false;").append("\n")
		.append("\t\t").append("}else{").append("\n")
		.append("\t\t").append("    Pattern pattern = Pattern.compile(\"-?[0-9]+.?[0-9]+\"); ").append("\n")
		.append("\t\t").append("    return pattern.matcher(str).matches();    ").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t").append(" } ").append("\n")
		.append("\t").append("").append("\n")
		.append("\t").append("public static InputStream getDownloadStream(String filename){").append("\n")
		.append("\t\t").append("InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(getTemplatePath(filename));").append("\n")
		.append("\t\t").append("if(is == null){").append("\n")
		.append("\t\t\t").append("throw new BizException(\"模板文件不存在!\");").append("\n")
		.append("\t\t").append("}").append("\n")
		.append("\t\t").append("return is;").append("\n")
		.append("\t").append("}").append("\n")
		.append("}").append("\n");

		File file = new File(Common.SAVE_PATH+File.separator+"util");
		if(!file.exists()){
			file.mkdirs();
		}
		Common.write(new File(file,"CommonUtil.java"), buff.toString());
		
		System.out.println("CommonUtil.java 已生成.....");
	}
	
	public static void main(String[] args) {
//		createDoMain(Common.DOMAIN_NAME,Common.filePath);
		
	}
}
